﻿using UnityEngine;
using UnityEngine.EventSystems;

namespace Controller
{
	public class ControllerButton : MonoBehaviour,IPointerDownHandler,IPointerUpHandler
	{
		
		public delegate void ButtonEvent();

		public ButtonEvent onClickEvent,pressedEvent;

		private bool isPressed;

		void Update(){
			if(isPressed){
				if(null != pressedEvent)
					pressedEvent();
			}
		}

		public void OnPointerDown( PointerEventData eventData ) {
			isPressed = true;
			if(null != onClickEvent)
				onClickEvent();
		}

		public void OnPointerUp( PointerEventData eventData ) {
			isPressed = false;
		}
	}
}

